<?php

require_once APP_PATH.'/Model/IndexModel.php';

class BaseController extends Controller {
	
	private $errorInfo;
	
	function __construct(){
		session_start();
		parent::__construct();
	
		if (isset($_POST['loginact'])&&$_POST['loginact']=='login'){
			$this->auth();
			$errorInfo = $this->errorInfo;
		}
		if (empty($_SESSION['admin'])||$_SESSION['admin']!='admin'){
			$cssPath = APP_PATH.'/FrontFile/Css';
			$jsPath = APP_PATH.'/FrontFile/Js';
			$imagesPath = APP_PATH.'/FrontFile/Images';
			require_once APP_PATH.'/Template/login.php';
		}
	}
	
	public function auth(){
		if (!isset($_POST['username'])||$_POST['username']!='uguke'){
			$this->errorInfo = '用户名不正确';
		} elseif (!isset($_POST['userpwd'])||substr(md5(md5($_POST['userpwd'])),0,30)!='f5e43cefa7309c3f73b2eef14d308d'){
			$this->errorInfo = '密码不正确';
		} else {
			$_SESSION['admin'] = 'admin';
		}
	}
	
	public function loginout(){
		unset($_SESSION['admin']);
		header('location:/admin.php');
	}
}